home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / inamedef.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  6.4 KB  |  173 lines

  1. /* Copyright (C) 1989, 1995, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: inamedef.h,v 1.2 2000/09/19 19:00:45 lpd Exp $ */
  20. /* Name table definition */
  21.  
  22. #ifndef inamedef_INCLUDED
  23. #  define inamedef_INCLUDED
  24.  
  25. #include "inameidx.h"
  26. #include "inamestr.h"
  27. #include "inames.h"
  28. #include "gsstruct.h"        /* for gc_state_t */
  29.  
  30. /*
  31.  * The name table machinery has two slightly different configurations:
  32.  * a faster one that limits the total number of names to 64K and allows
  33.  * names up to 16K in size, and a slightly slower one that limits
  34.  * the total to 4M and restricts names to 256 characters.
  35.  * The maximum number of names is 2^(16+EXTEND_NAMES)-1.
  36.  */
  37. #define max_name_extension_bits 6
  38. #if EXTEND_NAMES > max_name_extension_bits
  39. #  undef EXTEND_NAMES
  40. #  define EXTEND_NAMES max_name_extension_bits
  41. #endif
  42. /*       
  43.  * We capture the small algorithmic differences between these two
  44.  * configurations entirely in this header file;
  45.  * the implementation doesn't need any conditionals on EXTEND_NAMES.
  46.  */
  47. #define max_name_index (uint)((0x10000 << EXTEND_NAMES) - 1)
  48. /* As explained below, we distinguish name indices from name counts. */
  49. #define max_name_count max_name_index
  50.  
  51. /* ---------------- Structure definitions ---------------- */
  52.  
  53. /*
  54.  * Define the structure of a name.  The pvalue member implements an
  55.  * important optimization to avoid lookup for operator and other global
  56.  * names.
  57.  */
  58. struct name_s {
  59. /* pvalue specifies the definition status of the name: */
  60. /*      pvalue == pv_no_defn: no definitions */
  61. #define pv_no_defn ((ref *)0)
  62. /*      pvalue == pv_other: other status */
  63. #define pv_other ((ref *)1)
  64. /*      pvalue != pv_no_defn, pvalue != pv_other: pvalue is valid */
  65. #define pv_valid(pvalue) ((unsigned long)(pvalue) > 1)
  66.     ref *pvalue;        /* if only defined in systemdict or */
  67.                 /* userdict, this points to the value */
  68. };
  69.  
  70. /*typedef struct name_s name; *//* in iref.h */
  71.  
  72. /*
  73.  * Define the structure of a name table.  Normally we would make this
  74.  * an opaque type, but we want to be able to in-line some of the
  75.  * access procedures.
  76.  *
  77.  * The name table is a two-level indexed table, consisting of
  78.  * sub-tables of size nt_sub_size each.
  79.  *
  80.  * First we define the name sub-table structure.
  81.  */
  82. #define nt_log2_sub_size NT_LOG2_SUB_SIZE /* in inameidx.h */
  83. # define nt_sub_size (1 << nt_log2_sub_size)
  84. # define nt_sub_index_mask (nt_sub_size - 1)
  85. typedef struct name_sub_table_s {
  86.     name names[NT_SUB_SIZE];    /* must be first */
  87. #ifdef EXTEND_NAMES
  88.     uint high_index;        /* sub-table base index & (-1 << 16) */
  89. #endif
  90. } name_sub_table;
  91.  
  92. /*
  93.  * Now define the name table itself.
  94.  * This must be made visible so that the interpreter can use the
  95.  * inline macros defined below.
  96.  */
  97. struct name_table_s {
  98.     uint free;            /* head of free list, which is sorted in */
  99.                 /* increasing count (not index) order */
  100.     uint sub_next;        /* index of next sub-table to allocate */
  101.                 /* if not already allocated */
  102.     uint perm_count;        /* # of permanent (read-only) strings */
  103.     uint sub_count;        /* index of highest allocated sub-table +1 */
  104.     uint max_sub_count;        /* max allowable value of sub_count */
  105.     uint name_string_attrs;    /* imemory_space(memory) | a_readonly */
  106.     gs_memory_t *memory;
  107.     uint hash[NT_HASH_SIZE];
  108.     struct sub_ {        /* both ptrs are 0 or both are non-0 */
  109.     name_sub_table *names;
  110.     name_string_sub_table_t *strings;
  111.     } sub[max_name_index / nt_sub_size + 1];
  112. };
  113. /*typedef struct name_table_s name_table; *//* in inames.h */
  114.  
  115. /* ---------------- Procedural interface ---------------- */
  116.  
  117. /*
  118.  * Convert between names, indices, and strings.  Note that the inline
  119.  * versions, but not the procedure versions, take a name_table argument.
  120.  */
  121.         /* index => string */
  122. #define names_index_string_inline(nt, nidx)\
  123.   ((nt)->sub[(nidx) >> nt_log2_sub_size].strings->strings +\
  124.    ((nidx) & nt_sub_index_mask))
  125.         /* ref => string */
  126. #define names_string_inline(nt, pnref)\
  127.   names_index_string_inline(nt, names_index_inline(nt, pnref))
  128.         /* ref => index */
  129. #if EXTEND_NAMES
  130. #  define names_index_inline(nt_ignored, pnref)\
  131.      ( ((const name_sub_table *)\
  132.     ((pnref)->value.pname - (r_size(pnref) & nt_sub_index_mask)))->high_index + r_size(pnref) )
  133. #else
  134. #  define names_index_inline(nt_ignored, pnref) r_size(pnref)
  135. #endif
  136. #define names_index(nt_ignored, pnref) names_index_inline(nt_ignored, pnref)
  137.         /* index => name */
  138. #define names_index_ptr_inline(nt, nidx)\
  139.   ((nt)->sub[(nidx) >> nt_log2_sub_size].names->names +\
  140.    ((nidx) & nt_sub_index_mask))
  141.         /* index => ref */
  142. #define names_index_ref_inline(nt, nidx, pnref)\
  143.   make_name(pnref, nidx, names_index_ptr_inline(nt, nidx));
  144. /* Backward compatibility */
  145. #define name_index_inline(pnref) names_index_inline(ignored, pnref)
  146. #define name_index_ptr_inline(nt, pnref) names_index_ptr_inline(nt, pnref)
  147. #define name_index_ref_inline(nt, nidx, pnref)\
  148.   names_index_ref_inline(nt, nidx, pnref)
  149.         /* name => ref */
  150. /* We have to set the space to system so that the garbage collector */
  151. /* won't think names are foreign and therefore untraceable. */
  152. #define make_name(pnref, nidx, pnm)\
  153.   make_tasv(pnref, t_name, avm_system, (ushort)(nidx), pname, pnm)
  154.  
  155. /* ------ Garbage collection ------ */
  156.  
  157. /* Unmark all non-permanent names before a garbage collection. */
  158. void names_unmark_all(P1(name_table * nt));
  159.  
  160. /* Finish tracing the name table by putting free names on the free list. */
  161. void names_trace_finish(P2(name_table * nt, gc_state_t * gcst));
  162.  
  163. /* ------ Save/restore ------ */
  164.  
  165. /* Clean up the name table before a restore. */
  166. #ifndef alloc_save_t_DEFINED    /* also in isave.h */
  167. typedef struct alloc_save_s alloc_save_t;
  168. #  define alloc_save_t_DEFINED
  169. #endif
  170. void names_restore(P2(name_table * nt, alloc_save_t * save));
  171.  
  172. #endif /* inamedef_INCLUDED */
  173.